<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://doc.hyperf.io
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
 */

namespace App\Controller;
//引用对应的命名空间
use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;
use Session;

class IndexController extends AbstractController
{
    public function index()
    {
        $user = $this->request->input('user', 'Hyperf is OK');
        $method = $this->request->getMethod();

        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }

    public function hello(){
        return ['statue'=>200,'msg'=>'It is successful!',];
    }

    public function captcha()
    {
   
        // Will build phrases of 5 characters, only digits
        $phraseBuilder = new PhraseBuilder(4, '0123456789');

        // // Pass it as first argument of CaptchaBuilder, passing it the phrase
        // // builder
        $builder = new CaptchaBuilder(null, $phraseBuilder);
        $builder->build(150, 40);
        $content = $builder->get();
        return $content;
    }

    // 验证码字符生成,默认4位
    public function vcode(){
        $size = 4;
        $code_array = array(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
        $random_key = array();
        for ($i = 0; $i < $size; $i++){
            $key = array_rand($code_array,1);
            array_push($random_key,$code_array[$key]);
        }
        // 数组转字符串
        $verification_code = implode('',$random_key);
        return $verification_code;
    }

}
